/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.univcasa.managing.util;

import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.Name;
import javax.naming.NameNotFoundException;
import javax.naming.NameParser;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import javax.naming.directory.Attribute;
import javax.naming.directory.Attributes;
import javax.naming.directory.BasicAttribute;
import javax.naming.directory.BasicAttributes;
import javax.naming.directory.DirContext;
import javax.naming.directory.ModificationItem;
import javax.naming.directory.SearchControls;

/**
 *
 * @author issam
 */
public class User implements DirContext {
   String id;
   String dn;
   Attributes myAttrs = new BasicAttributes(true);
   Attribute oc = new BasicAttribute("objectclass");

public User(String dn, String givenname,String sn,
              String mail, String etab){
      this.dn=dn;
      id = dn;
      oc.add("inetOrgPerson");
      oc.add("organizationalPerson");
      oc.add("inetOrgPerson");
      oc.add("postfixPerson");
      oc.add("supannPerson");
      oc.add("eduPerson");
      String cn = givenname+" "+sn;
      myAttrs.put(oc);
      myAttrs.put("uid",dn);
      myAttrs.put("supannAliasLogin",dn);
      myAttrs.put("cn",cn);
      myAttrs.put("sn",sn);
      myAttrs.put("givenname",givenname);
      myAttrs.put("mail",mail);
      myAttrs.put("supannListeRouge","FALSE");      
      myAttrs.put("displayName",cn);
      myAttrs.put("supannOrganisme",etab);
      myAttrs.put("eduPersonPrincipalName", dn+"@univcasa.ma");

   }

public User(String dn, String givenname,String sn,
              String mail,String tel,String fax){
      this.dn=dn;
      id = dn;
      oc.add("inetOrgPerson");
      oc.add("organizationalPerson");
      oc.add("inetOrgPerson");
      oc.add("postfixPerson");
      oc.add("supannPerson");
      oc.add("eduPerson");
      String cn = givenname+" "+sn;
      myAttrs.put(oc);
      myAttrs.put("uid",dn);
      myAttrs.put("cn",cn);
      myAttrs.put("sn",sn);
      myAttrs.put("givenname",givenname);
      myAttrs.put("mail",mail);
      myAttrs.put("telephoneNumber",tel);
      myAttrs.put("facsimiletelephoneNumber",fax);
   }

public void completerCompteEtudiant(String apogee,String cne,String diplome,String etape,String adresse,String sexe,String pass){
    myAttrs.put("supannEtuId",apogee);
    myAttrs.put("userPassword",pass);
    myAttrs.put("supannCodeINE",cne);
    myAttrs.put("supannEtuDiplome",diplome);
    myAttrs.put("supannEtuEtape", etape );
    myAttrs.put("supannCivilite", sexe );
    myAttrs.put("supannAffectation",diplome);
    myAttrs.put("description","etudiant(e)" );
    myAttrs.put("eduPersonPrimaryAffiliation", "student");    
    myAttrs.put("mail",dn+"@etude.univcasa.ma");
    Attribute eduAffil = new BasicAttribute("eduPersonAffiliation");
    eduAffil.add("member");
    eduAffil.add("student");
    myAttrs.put(eduAffil);
}

public void completerComptePersonnel(String som,String sexe,String pass){
    myAttrs.put("supannEmpId",som);
    myAttrs.put("userPassword",pass);
    myAttrs.put("supannCivilite", sexe );
    myAttrs.put("description","personnel" );
    myAttrs.put("eduPersonPrimaryAffiliation", "employee");
    myAttrs.put("mail",dn+"@etude.univcasa.ma");
    Attribute eduAffil = new BasicAttribute("eduPersonAffiliation");
    eduAffil.add("member");
    eduAffil.add("employee");
    myAttrs.put(eduAffil);
}

public void addAttribs(){

}

public String getDn() {
        return dn;
    }

public Attributes getAttributes(String name) throws NamingException {
      if (! name.equals("")){
         throw new NameNotFoundException();
      }
      return myAttrs;
   }
public Attributes getAttributes(Name name) throws NamingException {
      return getAttributes(name.toString());
   }
public Attributes getAttributes(String name, String[] ids)
                                            throws NamingException {
      if(! name.equals(""))
         throw new NameNotFoundException();
      Attributes answer = new BasicAttributes(true);
      Attribute target;
      for (int i = 0; i < ids.length; i++){
         target = myAttrs.get(ids[i]);
         if (target != null){
            answer.put(target);
         }
      }
      return answer;
   }
public Attributes getAttributes(Name name, String[] ids)
                                              throws NamingException {
      return getAttributes(name.toString(), ids);
   }

    public void modifyAttributes(Name name, int mod_op, Attributes attrs) throws NamingException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void modifyAttributes(String name, int mod_op, Attributes attrs) throws NamingException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void modifyAttributes(Name name, ModificationItem[] mods) throws NamingException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void modifyAttributes(String name, ModificationItem[] mods) throws NamingException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void bind(Name name, Object obj, Attributes attrs) throws NamingException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void bind(String name, Object obj, Attributes attrs) throws NamingException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void rebind(Name name, Object obj, Attributes attrs) throws NamingException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void rebind(String name, Object obj, Attributes attrs) throws NamingException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public DirContext createSubcontext(Name name, Attributes attrs) throws NamingException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public DirContext createSubcontext(String name, Attributes attrs) throws NamingException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public DirContext getSchema(Name name) throws NamingException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public DirContext getSchema(String name) throws NamingException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public DirContext getSchemaClassDefinition(Name name) throws NamingException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public DirContext getSchemaClassDefinition(String name) throws NamingException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public NamingEnumeration search(Name name, Attributes matchingAttributes, String[] attributesToReturn) throws NamingException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public NamingEnumeration search(String name, Attributes matchingAttributes, String[] attributesToReturn) throws NamingException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public NamingEnumeration search(Name name, Attributes matchingAttributes) throws NamingException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public NamingEnumeration search(String name, Attributes matchingAttributes) throws NamingException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public NamingEnumeration search(Name name, String filter, SearchControls cons) throws NamingException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public NamingEnumeration search(String name, String filter, SearchControls cons) throws NamingException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public NamingEnumeration search(Name name, String filterExpr, Object[] filterArgs, SearchControls cons) throws NamingException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public NamingEnumeration search(String name, String filterExpr, Object[] filterArgs, SearchControls cons) throws NamingException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public Object lookup(Name name) throws NamingException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public Object lookup(String name) throws NamingException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void bind(Name name, Object obj) throws NamingException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void bind(String name, Object obj) throws NamingException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void rebind(Name name, Object obj) throws NamingException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void rebind(String name, Object obj) throws NamingException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void unbind(Name name) throws NamingException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void unbind(String name) throws NamingException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void rename(Name oldName, Name newName) throws NamingException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void rename(String oldName, String newName) throws NamingException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public NamingEnumeration list(Name name) throws NamingException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public NamingEnumeration list(String name) throws NamingException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public NamingEnumeration listBindings(Name name) throws NamingException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public NamingEnumeration listBindings(String name) throws NamingException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void destroySubcontext(Name name) throws NamingException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void destroySubcontext(String name) throws NamingException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public Context createSubcontext(Name name) throws NamingException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public Context createSubcontext(String name) throws NamingException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public Object lookupLink(Name name) throws NamingException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public Object lookupLink(String name) throws NamingException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public NameParser getNameParser(Name name) throws NamingException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public NameParser getNameParser(String name) throws NamingException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public Name composeName(Name name, Name prefix) throws NamingException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public String composeName(String name, String prefix) throws NamingException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public Object addToEnvironment(String propName, Object propVal) throws NamingException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public Object removeFromEnvironment(String propName) throws NamingException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public Hashtable getEnvironment() throws NamingException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void close() throws NamingException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public String getNameInNamespace() throws NamingException {
        throw new UnsupportedOperationException("Not supported yet.");
    }
}